package com.hp.controller;

import com.hp.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author cksh
 * @create 2021-07-08 21:31
 */
@RestController
public class FileController {
    @Autowired
    FileService fileService;

    @PostMapping("/upload/headPhoto")
    public Map<String, Object> uploadHeadPhoto(MultipartFile headPhoto, int userId, HttpSession session) {
        return fileService.uploadHeadPhoto(headPhoto, "D:/houseRent/images/user/" + userId + "/", userId);
    }

    @PostMapping("/upload/housePhoto")
    public Map<String, Object> uploadHousePhoto(MultipartFile []file, int houseId, HttpSession session) {

        return fileService.uploadHousePhoto(file[0], "D:/houseRent/images/house/" + houseId + "/", houseId);
    }

    @PostMapping("/upload/voice")
    public Map<String, Object> uploadVoice(MultipartFile voiceFile, int fromId, int toId, HttpSession session) {
        System.out.println(voiceFile);
        return fileService.uploadVoice(voiceFile, "D:/houseRent/images/voice/" + fromId + "-" + toId + "/", "http://192.168.43.54:8002/images/voice/" + fromId + "-" + toId + "/");
    }

    @PostMapping("/upload/news/img")
    public Map<String, Object> uploadNewsImg(MultipartFile img, int fromId, int toId, HttpSession session) {
        return fileService.uploadNewsImg(img, "D:/houseRent/images/news/images/" + fromId + "-" + toId + "/", "http://192.168.43.54:8002/images/news/images/" + fromId + "-" + toId + "/");
    }

    @PostMapping("/upload/applyPhoto")
    public Map<String, Object> uploadApplyPhoto(MultipartFile applyPhoto, int applyId, HttpSession session) {
        return fileService.uploadApplyPhoto(applyPhoto, "D:\\houseRent\\images\\apply\\" + applyId + "\\", applyId);
    }

}
